//------------Sonic CD BGEffects Script-------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

//-------Aliases-------//
#alias 16: TYPE_BGEFFECTS


sub ObjectDraw
	switch Object.Value6
	case 0
		if Object[4].Value1>=20
			Object.Value6++
		endif
		break
	case 1
		if Object[4].Value1<20
			PlayMusic(2)
			Object.Value6++
		endif
		break
	endswitch
	if Object[30].Type==TypeName[StageFinish]
		if Object[30].PropertyValue==0
			SetMusicTrack("SS45FinishBad.ogg",1,2146260)
		endif
	endif
	TempValue1=Object.Value2
	TempValue2=TileLayer[0].Angle
	if TempValue1<TempValue2
		TempValue3=TempValue2
		TempValue3-=TempValue1
		if TempValue3>256
			TempValue1+=512
		endif
	else
		TempValue3=TempValue1
		TempValue3-=TempValue2
		if TempValue3>256
			TempValue2+=512
		endif
	endif
	TempValue0=TempValue1
	TempValue0-=TempValue2
	Object.Value2=TileLayer[0].Angle
	TempValue0<<=15
	HParallax[0].ScrollPos+=TempValue0
	TempValue0<<=1
	HParallax[1].ScrollPos+=TempValue0
	if TileLayer[0].Angle==0
		TempValue0=0
	else
		TempValue0=512
		TempValue0-=TileLayer[0].Angle
	endif
	TempValue0<<=1
	TempValue0&=255
	FlipSign(TempValue0)
	while TempValue0<Screen.XSize
		DrawSpriteScreenXY(0,TempValue0,8)
		TempValue0+=256
	loop
endsub


sub ObjectStartup
	SetMusicTrack("SS4.ogg",0,44100)
	SetMusicTrack("SS45FinishGood.ogg",1,294100)
	SetMusicTrack("SS4Pinch.ogg",2,179100)
	Stage.XBoundary1=54525952
	Stage.XBoundary2=213909504
	Stage.YBoundary1=54525952
	Stage.YBoundary2=213909504
#platform: HW_Rendering
	LoadSpriteSheet("Special/SSMap4.gif")
#endplatform
	LoadSpriteSheet("Special/ss4bg3.gif")
	SpriteFrame(0,0,256,128,0,0)
	ArrayPos0=32
	while ArrayPos0<1056
		if Object[ArrayPos0].Type==TypeName[BGEffects]
			Object[ArrayPos0].Priority=1
			Object[ArrayPos0].DrawOrder=2
			Object[ArrayPos0].Value2=368
		endif
		ArrayPos0++
	loop
endsub

sub RSDK
	LoadSpriteSheet("Global/Display.gif")
	SetEditorIcon(Icon0,SingleIcon,-16,-16,32,32,1,143)
endsub
